package com.lovo;

import javax.swing.*;
import java.awt.event.*;

public class Test03 extends JFrame implements ActionListener, MouseListener {
    private JTextField textField;
    private JButton btn1;
    private JButton btn2;
    public Test03(){

        this.setLayout(null);

        btn1 = new JButton("+");
        btn1.setBounds(0,0,50,20);
        this.add(btn1);
        btn1.addActionListener(this);

        textField = new JTextField("0");
        textField.setBounds(50,0,100,20);
        this.add(textField);
        textField.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                System.out.println("entered");
            }
        });

        btn2 = new JButton("-");
        btn2.setBounds(150,0,50,20);
        this.add(btn2);
        btn2.addActionListener(this);

        this.setSize(800,600);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new Test03();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("action:" + e.getActionCommand());

        if(e.getSource() == btn1){
            System.out.println("点击确定");
            textField.setText(Integer.parseInt(textField.getText()) + 1 + "");

        }else if(e.getSource() == btn2){
            System.out.println("点击取消");
            textField.setText(Integer.parseInt(textField.getText()) - 1 + "");
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println(e.getX() + " " + e.getY());
        System.out.println(e.getXOnScreen() + " " + e.getYOnScreen());
    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
